home *** CD-ROM | disk | FTP | other *** search
/ CD Exchange / CD Exchange - Volume 1.iso / d.t.p / utils / propage / donsgenies / donsgenies.lha / Don'sGenies / Booklet.pprx < prev    next >
Text File  |  1993-08-07  |  5KB  |  140 lines

  1. /*
  2. This genie will rearrange a document designed as double-page spreads to fit on the sheets of a simple stapled booklet. In this document, the first page has the first page on the right and the last on the left; the rest have pairs in normal order (2 & 3, 4 & 5, etc). It only works for Postscript output (which may be to a non-Postscript printer via Post). The pages are arranged so you can print the first half of the document on one side of the paper and then turn the paper over for the other half.
  3. Written by Don Cox ©1993 Revised March 93. Not public domain.
  4. */
  5.  
  6. cr = '0a'x
  7. call SafeEndEdit.rexx()
  8. call ppm_AutoUpdate(0)
  9. oldpsout = ppm_GetPSOutput()
  10. call ppm_SetPSFontDownload(0)
  11. call ppm_SetBatchMode(1)
  12. prevdoc  = ppm_GetDocName()
  13. if ppm_DocChanged() then
  14. do
  15.     if ppm_SavedDate() = "Not Saved" then prevdoc = ""
  16.     if ppm_Inform(2, "You must save the current document first. Should I save and continue?", "Cancel", "Ok") then
  17.                 call ppm_SaveDocument(prevdoc)
  18.     else
  19.             exit_msg("Aborted by User")
  20.     prevdoc = ppm_GetDocName()
  21. end
  22.  
  23. totalpages = ppm_NumPages()
  24. if totalpages = 0 then exit_msg("No pages")
  25. lpos = lastpos("/",prevdoc)  /* Find end of pathname */
  26. if lpos = 0 then lpos = lastpos(":",prevdoc)
  27. docname = substr(prevdoc,lpos+1)  /* Strip off pathname */
  28. pathname = substr(prevdoc,1,length(prevdoc)-length(docname))
  29. call ppm_SetDocName(docname||".bklt")
  30. if length(docname)>30 then do
  31.     docname = delstr(docname,1,length(docname)-30)
  32.     call ppm_SetDocName(docname)  /* File name only */
  33.     end
  34. newname = ppm_GetDocName()   /* Full name including path */
  35.  
  36. /* Set all pages to size of largest */
  37. if totalpages>1 then do
  38.     oldpageX = word(ppm_GetPageSize(1),1)
  39.     oldpageY = word(ppm_GetPageSize(1),2)
  40.     diff = 0   /* flag for different page sizes */
  41.     do i = 2 to totalpages
  42.         pageX = word(ppm_GetPageSize(i),1)
  43.         pageY = word(ppm_GetPageSize(i),2)
  44.         if pageX ~= oldpageX | pageY ~= oldpageY then do
  45.             diff = diff+1
  46.             oldpageX = max(pageX,oldpageX)
  47.             oldpageY = max(pageY,oldpageY)
  48.             end
  49.         end
  50. if diff ~=0 then do
  51.     do i =1 to totalpages
  52.         call ppm_SetPageSize(i,oldpageX,oldpageY)
  53.         end
  54.     exit_msg("Pages Resized. Check boxes & try again")
  55.     end
  56. end
  57.  
  58. /* Save all pages as .eps files */
  59. call ppm_SetPSEPSF(1)
  60. length2 = length(newname)
  61. epsname = substr(newname,1,length2-5) /* strip off ".bklt" */
  62. do i = 1 to totalpages
  63.      /* .eps is only as big as the boxes, not the page,so make a page-size box. */
  64.     newpage = ppm_GotoPage(i)
  65.     pagebox = ppm_CreateBox(0,0,oldpageX,oldpageY,0)
  66.     call ppm_SetPSOutputOrient(i,1)
  67.     call ppm_SetPSPageSize(oldpageX,oldpageY)
  68.     call ppm_SetPSOutput(epsname||i||".eps")
  69.     success = ppm_PrintPagePS(i,1,1)
  70.     if success = 0 then exit_msg("Failed saving .eps of page "i)
  71.     end
  72. /*call exit_msg("temporary stop") /* testing */*/
  73. call ppm_DeletePage(1,totalpages)
  74. freshpage = ppm_CreatePage(1,1,0,0)
  75. call ppm_SetPageSize(1,oldpageX,oldpageY)
  76. /* The next 2 lines assume you are printing to a normal A4 or A3 printer */
  77. if oldpageX>oldpageY then call ppm_SetPSPageSize(oldpageY,oldpageX)
  78. if oldpageX>oldpageY then call ppm_SetPSOutputOrient(1,2)
  79. done = ppm_CopyPage(1,1,totalpages-1)
  80.  
  81. trace r
  82.  
  83. offset = oldpageX/2
  84. offset = -offset
  85. pages = 2*totalpages /* 2 pages on each side of the paper */
  86. do i = 1 to totalpages
  87.     newpage = ppm_GotoPage(i)
  88.     Lbox = ppm_CreateBox(0,0,oldpageX/2,oldpageY,0)
  89.     Rbox = ppm_CreateBox(oldpageX/2,0,oldpageX/2,oldpageY,0)
  90.  
  91.     if i//2=1 then   /* check for odd number pages */
  92.         do
  93.         j = (i-1)/2
  94.         if j=0 then j=totalpages
  95.         k = (totalpages+1)-j  /* Formula for left page, odd sides */
  96.         m = (i+1)/2  /* Right page, odd sides */
  97.         done = ppm_ImportEPSF(Lbox,epsname||k||".eps")
  98. /*        if done = 0 then exit_msg("Trouble importing "epsname||k||".eps")
  99. n.b. Had to remove error check because of bug in ProPage 4.1  */
  100.         done = ppm_ImportEPSF(Rbox,epsname||m||".eps")
  101.  /*       if done = 0 then exit_msg("Trouble importing "epsname||m||".eps")*/
  102.         end
  103.     else do
  104.         n = (i/2)+1  /* Left page, even sides */
  105.         p = (totalpages+1)-(i/2)  /* Right box, even sides */
  106.         done = ppm_ImportEPSF(Rbox,epsname||p||".eps")
  107. /*        if done = 0 then exit_msg("Trouble importing "epsname||p||".eps")*/
  108.         done = ppm_ImportEPSF(Lbox,epsname||n||".eps")
  109. /*        if done = 0 then exit_msg("Trouble importing "epsname||n||".eps")*/
  110.         end
  111.   
  112.     
  113.     /* Must set scale before offset as it scales the offset */
  114.     call ppm_SetBoxScale(Lbox,1,1)
  115.     call ppm_SetBoxScale(Rbox,1,1)
  116.     call ppm_SetBoxOffset(Rbox,offset,0)
  117.     end
  118.  
  119.  
  120. /* Separate the odd and even sides for double-sided printing */
  121. do i = totalpages-1 to totalpages/2 by -1
  122.         done = ppm_MovePage(i,1)
  123.     end
  124. newpage = ppm_GotoPage(1)
  125. call exit_msg("Done")
  126. end
  127.  
  128. exit_msg: procedure expose oldpsout
  129. do
  130. parse arg message
  131.     if message ~= '' then
  132.     call ppm_Inform(1, message,"Resume" )
  133.     call ppm_SetPSEPSF(0)
  134.     call ppm_SetPSOutput(oldpsout)
  135.     call ppm_AutoUpdate(1)
  136.     call ppm_ClearStatus()
  137.     call ppm_SetBatchMode(1)
  138.     exit
  139. end
  140.